﻿Imports MeoTom.Core.BLL
Imports MeoTom.Core

Namespace Control

    Partial Public Class LinkCategory1
        Inherits UserControl
        Public Lc As New LinkCat()
        Public Util2 As New Utilities.Common()

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim previousPage As String = ""
            If Request.QueryString.ToString = vbNullString Then
                previousPage = Server.UrlEncode(Request.ServerVariables("PATH_INFO"))
            Else
                previousPage = Server.UrlEncode(Request.ServerVariables("PATH_INFO") & "?" & Request.QueryString.ToString())
            End If
            Util2.ValidateLogin(previousPage)

            BindGrid()
        End Sub

        Public Sub BindGrid()
            grvLinkCat.DataSource = lc.GetAll()
            grvLinkCat.DataBind()
        End Sub

        Public Function WriteChk(ByVal vId As String)
            Dim strOut As String = ""
            If vId = "1" Then
                strOut = ""
            Else
                strOut = "<input type=""checkbox"" onfocus=""this.blur();"" name=""cboCheckLinkCat"" value=""" & vId & """ />"
            End If
            Return strOut
        End Function

        Public Function WriteLnkDelete(ByVal vId As String, ByVal vName As String)
            Dim strOut As String = ""
            If vId = "1" Then
                strOut = ""
            Else
                strOut = "&nbsp;|&nbsp;<a href=""LinkCategory.aspx?action=Delete&ID=" & vId & """ title=""Delete this Link Category"" onclick=""javascript:return Util.ConfirmDeleteArticle('" & vName & "');"">Delete</a>"
            End If
            Return strOut
        End Function

        Private Sub btnApply_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnApply.Click
            If Request.Form("selectedAction0") = "2" Or Request.Form("selectedAction1") = "2" Then
                'Delete
                For Each str As String In Regex.Split(Request.Form("cboCheckLinkCat"), ",")
                    If util2.IsNumeric(str) Then
                        DeleteCat(Integer.Parse(str))
                    End If
                Next
                lc.WriteLinkCat(5)
                BindGrid()
            End If
        End Sub

        Private Sub btnApply2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnApply2.Click
            btnApply_Click(sender, e)
        End Sub

        Public Sub DeleteCat(ByVal vId As Integer)
            lc.CatID = vId
            lc.Delete()
        End Sub

        Private Sub btnCreate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCreate.Click
            lc.CatName = util2.NoHTML(txtTitle.Text)
            lc.Description = util2.NoHTML(txtDesc.Text)
            txtDesc.Text = ""
            txtTitle.Text = ""
            lc.Create()
            lc.WriteLinkCat(5)
            BindGrid()
        End Sub
    End Class
End Namespace